﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GU.WebERP.Model;
using System.Data;
using GU.WebERP.Dict;
using GU.WebERP.Core.Utils;

namespace GU.WebERP.DAL
{
    public class DAL_Dim_Menu : JnsFramework.Core.TableOperating
    {
        readonly Model_Dim_Menu _modelITM_Dim_Menu = new Model_Dim_Menu();

        public DAL_Dim_Menu()
        {
            base.DBKey = "GU.ERPDb";
        }

        protected override JnsFramework.Common.IModel GetTableModel()
        {
            return _modelITM_Dim_Menu;
        }

        public List<Model_Dim_Menu> GetAll()
        {
            DataTable dt = this.Query.And(Dict_Dim_Menu.Disabled).IsEqualTo(0).OrderAsc(Dict_Dim_Menu.Sort).ToDataTable();
            return ConvertDtHelper<Model_Dim_Menu>.GetModelList(dt);
        }

        public Model_Dim_Menu GetSingle(int menuId)
        {
            DataTable dt = this.Query.And(Dict_Dim_Menu.MenuId).IsEqualTo(menuId).And(Dict_Dim_Menu.Disabled).IsEqualTo(0).ToDataTable();
            return Model_Dim_Menu.TableToModel(dt);
        }

        public List<Model_Dim_Menu> GetAllByIds(string ids)
        {
            if (string.IsNullOrWhiteSpace(ids)) return null;
            DataTable dt = this.Query.And(Dict_Dim_Menu.Disabled).IsEqualTo(0).And(Dict_Dim_Menu.MenuId).In(ids).OrderAsc(Dict_Dim_Menu.Sort).ToDataTable();
            return ConvertDtHelper<Model_Dim_Menu>.GetModelList(dt);
        }
    }
}
